import com.lbi.core.events.Event;
import com.lbi.core.helper.Attach;
import com.lbi.core.helper.Delegate;
import com.lbi.core.view.Loader;
import com.lbi.framework.mvc.collection.Selectable;
import com.lbi.framework.mvc.view.ViewBase;
import com.lbi.typography.TypographyHelper;

import example.app.helpers.Typography;
import example.app.models.Person;
import com.lbi.debug.Log;
import com.lbi.animation.util.Easing;
import flash.filters.BlurFilter;
import com.lbi.framework.mvc.collection.Collection;
import flash.geom.Point;
import example.app.views.people.PeopleMenuView;
import flash.filters.DropShadowFilter;
/**
 * @author michaelforrest
 */
class example.app.views.people.PersonThumbnailView extends ViewBase {
	// this is a view of a person, so...
	private var person : Person;
	private var people : Collection;

	// view elements
	private var photo : Loader;
	private var label : TextField;
	
	private var __highlight:Number;

	public function get highlight():Number{
		return __highlight;
	}
	public function set highlight(v:Number):Void{
		__highlight = v;
		var shadow : Number = v*10;
		filters = [	new DropShadowFilter(shadow,45,0x666666)];
		label.text = person.name.substr(0,person.name.length*v);
		_y = -shadow;
		_alpha = v*50 + 50;
	}

	public static function create ( $person : Person, $parent : MovieClip, $depth : Number ) : PersonThumbnailView
	{
		return Attach.MovieClipClass($parent,PersonThumbnailView, $depth, [$person]);     
	}
	function PersonThumbnailView($person : Person) {
		super();
		person = $person;
		people = Person.people;
		addPhoto();
		addLabel();
		highlight = 0;
		
		animator.registerTransition("highlight");
		
		setRollOvers(doRollOver,doRollOut);
		
		person.registerEvents(this,	[Selectable.SELECTED,
									 Selectable.DESELECTED],
								"PersonThumbnailView");
		
	}
	private function addPhoto() : Void {
		photo = Loader.create(this,getNextHighestDepth());
		photo.load(person.image_url);
	}
	private function addLabel() : Void {
		var style : Typography = new Typography("ToolTip"); 
		label = Attach.TextField(this,style,getNextHighestDepth());
		label.text = person.name;
		TypographyHelper.fitHorizontally(label);
	}

	private function doRollOver() : Void {
		animator.change("highlight").setFrames(3).setEasing(Easing.linearTween);
		animator.highlight = 1;
	}
	private function doRollOut() : Void {
		// don't want a rollout if the object is selected
		if(person.isSelected()) return; 
		animator.change("highlight").setFrames(10).setEasing(Easing.easeOutCirc);
		animator.highlight = 0;
	}
	private function onPress(): Void{
		Person.people.select(person);	
	}
	private function respondToSelected() : Void {
		doRollOver();
	}
	private function respondToDeselected () : Void {
		doRollOut();
	}

}